Completed
Push — master ( 046036...9abb37 )
by Patrick
03:46
created

groups.js ➔ onGroupTableBodyClick   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 11
rs 9.4285
1
function groupExecute()
2
{
3
    var action;
4
    var selected = [];
5
    switch($("#group_action")[0].value)
6
    {
7
        default:
0 ignored issues
show
Coding Style Comprehensibility introduced by
The default case is not the last statement in this switch statement. For the sake of readability, you might want to move it to the end of the statement.
Loading history...
8
        case "none":
9
            return;
10
        case "del":
11
            action = "delete";
12
            break;
13
        case "new":
14
            window.location = "group_new.php";
15
            break;
16
    }
17
    var selected_rows = $('#group_table tr.selected');
18
    if(selected_rows.length < 1)
19
    {
20
        return;
21
    }
22
    for(var i = 0; i < selected_rows.length; i++)
23
    {
24
        selected.push(selected_rows[i].childNodes[0].innerHTML);
25
    }
26
    $.ajax({
27
        url: 'ajax/sessions.php',
28
        data: {'sids':selected,'action':action},
29
        type: 'post',
30
        dataType: 'json',
31
        success: session_exec_done});
0 ignored issues
show
Bug introduced by
The variable session_exec_done seems to be never declared. If this is a global, consider adding a /** global: session_exec_done */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
32
}
33
34
function renderGroupName(data)
35
{
36
    return '<a href="group_edit.php?gid='+data+'">'+data+'</a>';
37
}
38
39
function onGroupTableBodyClick()
40
{
41
    if($(this).hasClass('selected')) 
42
    {
43
        $(this).removeClass('selected');
44
    }
45
    else 
46
    {
47
        $(this).addClass('selected');
48
    }
49
}
50
51
function do_groups_init()
52
{
53
    if($("#group_table").length > 0)
54
    {
55
        $("#group_table").dataTable({
56
            'ajax': '../api/v1/groups?fmt=data-table',
57
            'columns': [
58
                {'data': 'cn', 'render': renderGroupName},
59
                {'data': 'description'}
60
            ]
61
        });
62
63
        $("#group_table tbody").on('click', 'tr', onGroupTableBodyClick);
64
    }
65
}
66
67
$(do_groups_init);
68